/***********************************************************************
 *
 * MODULE NAME:    rfcomm_pe.h
 * PROJECT CODE:   Port Entity include file
 * DESCRIPTION:    eCos Startup Code
 * MAINTAINER:     David Airlie
 * CREATION DATE:  1 May 2000
 *
 * SOURCE CONTROL: $Id: rfcomm_pe.h,v 1.2 2008/12/16 10:20:39 jianguo Exp $
 *
 * LICENSE:
 *     This source code is copyright (c) 2000-2002 RDA Microelectronics Inc.
 *     All rights reserved.
 *
 ***********************************************************************/
#ifndef RDABT_RFCOMM_PE_H
#define RDABT_RFCOMM_PE_H

//#include "platform_pe.h"
struct rdabt_rfcomm_os_port 
{
	int dummy;
};

struct rdabt_rfcomm_pe_port
{
  /* Bluetooth device address of the remote device - used if we are connector or connected */
  t_bdaddr remote_device_addr;

  /* Locally registered port number 0 for a port we have connected */
  u_int32 portnum;

  /* Multiplexer Instance */
  void *multi_inst;

  /* Local port name */
  char *portname;
  
  /* DLCI for a connected port */
  rdabt_t_rfcomm_dlci dlci;

  /* Status information for a port */
  /* For CREDIT_FLOW_CONTROL we can overload local_flow_state, 
     as this is not used in CREDIT_FLOW_CONTROL */
  rdabt_t_rfcomm_flow_state local_flow_state;
  rdabt_t_rfcomm_flow_state agg_flow_state;

  rdabt_t_rfcomm_port_params port_params;
  rdabt_t_rfcomm_dlc_params dlc_params;
  
  /* Callback function for notification of a connection to this entity */
  void (*port_cbfunc)(rdabt_t_rfcomm_schan, t_bdaddr, u_int8);

  struct rdabt_rfcomm_os_port os_spec;
};

#define RDABT_PORT_ENT_SERVER_REG 1
#define RDABT_PORT_ENT_CLIENT_CONN 2

/* These values must reflect values in rfcomm.h API header file */
#define RDABT_PORT_ENT_CONNECT 0
#define RDABT_PORT_ENT_DISCONNECT 1
#define RDABT_PORT_ENT_CONNECTFAILED 2

t_api PE_Init(void);
APIDECL1 t_api APIDECL2 PE_SrvRegisterPort(char *port, rdabt_t_rfcomm_schan *serv_chan, void (*port_callback)(rdabt_t_rfcomm_schan schan, t_bdaddr bd_addr, u_int8 connection_state));
APIDECL1 t_api APIDECL2 PE_SrvDeregisterPort(rdabt_t_rfcomm_schan schan);
APIDECL1 t_api APIDECL2 PE_SrvDisconnectPort(rdabt_t_rfcomm_schan schan);
APIDECL1 t_api APIDECL2 PE_CliConnectPort(t_bdaddr remote_bd_addr, rdabt_t_rfcomm_schan rem_schan, char *pName, void(*port_callback)(rdabt_t_rfcomm_schan schan, t_bdaddr bd_addr, u_int8 connection_state));
APIDECL1 t_api APIDECL2 PE_CliDisconnectPort(t_bdaddr remote_bd_addr, rdabt_t_rfcomm_schan serverchannel);
APIDECL1 t_api APIDECL2 PE_GetCIDFromConnection(t_bdaddr bdaddr, rdabt_t_rfcomm_dlci dlci, u_int16 *cid);

t_api PE_OS_SrvRegisterPort(struct rdabt_rfcomm_pe_port *pe_info);
t_api PE_OS_SrvDeregisterPort(struct rdabt_rfcomm_pe_port *pe_info);
t_api PE_OS_SrvDisconnectPort(struct rdabt_rfcomm_pe_port *pe_info);
t_api PE_OS_CliConnectPort_Allocate(struct rdabt_rfcomm_pe_port *pe_info);
t_api PE_OS_CliConnectPort_DeAllocate(struct rdabt_rfcomm_pe_port *pe_info);
t_api PE_OS_CliConnectPort_Enable(struct rdabt_rfcomm_pe_port *pe_info);
t_api PE_OS_CliDisconnectPort(struct rdabt_rfcomm_pe_port *pe_info);
t_api PE_OS_ReleasePort(struct rdabt_rfcomm_pe_port *pe_info);

void rdabt_rfcomm_init_pe_struct(struct rdabt_rfcomm_pe_port *pe_info);
void rdabt_rfcomm_init_pe_struct_params_default(struct rdabt_rfcomm_pe_port *pe_info);
void rdabt_rfcomm_free_pe_struct(struct rdabt_rfcomm_pe_port *pe_info);
t_api rdabt_rfcomm_pe_alloc_schan(rdabt_t_rfcomm_schan *p_schan);
int rdabt_rfcomm_pe_check_schan(rdabt_t_rfcomm_schan server_channel);
int rdabt_rfcomm_pe_free_schan(rdabt_t_rfcomm_schan server_channel);
int rdabt_rfcomm_pe_add_port_entity(struct rdabt_rfcomm_pe_port *self);
int rdabt_rfcomm_pe_remove_port_entity_by_portnum(struct rdabt_rfcomm_pe_port **port, u_int32 portnum);
int rdabt_rfcomm_pe_connect_port(t_bdaddr remote_bd_addr, rdabt_t_rfcomm_schan rem_schan, const char *pName, rdabt_t_rfcomm_dlci *dlci, struct rdabt_rfcomm_pe_port **pe_info_ptr, u_int16 max_frame_size, void (*port_callback)(rdabt_t_rfcomm_schan schan, t_bdaddr bd_addr, u_int8 connection_state));
int rdabt_rfcomm_pe_lookup_port_entity_by_portnum(struct rdabt_rfcomm_pe_port **port, u_int32 portnum);
int rdabt_rfcomm_pe_lookup_port_entity_by_dlci(struct rdabt_rfcomm_pe_port **port, rdabt_t_rfcomm_dlci dlci);
int rdabt_rfcomm_pe_lookup_port_entity_by_fd(struct rdabt_rfcomm_pe_port **port, int fd);
int rdabt_rfcomm_pe_lookup_port_entity_by_addr_and_dlci(struct rdabt_rfcomm_pe_port **port, t_bdaddr bd_addr, u_int8 dlci);
int rdabt_rfcomm_pe_remove_port_entity_by_addr_and_dlci(struct rdabt_rfcomm_pe_port **port, t_bdaddr bd_addr, u_int8 dlci);
t_api rdabt_rfcomm_pe_disconnect_remote_serverchannel(t_bdaddr remote_bd_addr, rdabt_t_rfcomm_schan serverchannel, struct rdabt_rfcomm_pe_port **pe_info_ptr);
int rdabt_rfcomm_pe_disconnect_local_server_channel(struct rdabt_rfcomm_pe_port **pe_info_ptr, rdabt_t_rfcomm_schan schan);
int rdabt_rfcomm_pe_remove_all_port_entity(void);
int port_ent_set_port_config(struct rdabt_rfcomm_pe_port *pe_info);

#endif

